/*
* 获取操作系统
* */
function getOSType () {
  let sUserAgent = navigator.userAgent;
  let isWin = (navigator.platform === "Win32") || (navigator.platform === "Windows");
  let isMac = (navigator.platform === "Mac68K") || (navigator.platform === "MacPPC") || (navigator.platform === "Macintosh") || (navigator.platform === "MacIntel");
  if (isMac) return "Mac";
  let isUnix = (navigator.platform === "X11") && !isWin && !isMac;
  if (isUnix) return "Unix";
  let isLinux = (String(navigator.platform).indexOf("Linux") > -1);
  if (isLinux) return "Linux";
  if (isWin) {
    if (sUserAgent.indexOf("Windows NT 5.0") > -1 || sUserAgent.indexOf("Windows 2000") > -1) return "Win2000";
    if (sUserAgent.indexOf("Windows NT 5.1") > -1 || sUserAgent.indexOf("Windows XP") > -1) return "WinXP";
    if (sUserAgent.indexOf("Windows NT 5.2") > -1 || sUserAgent.indexOf("Windows 2003") > -1) return "Win2003";
    if (sUserAgent.indexOf("Windows NT 6.0") > -1 || sUserAgent.indexOf("Windows Vista") > -1) return "WinVista";
    if (sUserAgent.indexOf("Windows NT 6.1") > -1 || sUserAgent.indexOf("Windows 7") > -1) return "Win7";
    if (sUserAgent.indexOf("Windows NT 10") > -1 || sUserAgent.indexOf("Windows 10") > -1) return "Win10";
  }
  return "None";
}

/*
*  获取浏览器类型和版本
* */
function getBrowserInfo () {
  let agent = navigator.userAgent.toLowerCase(),
    browser, version;
  //IE
  if (agent.indexOf("msie") > 0) {
    let regStr_ie = /msie [\d.]+;/gi;
    browser = "IE";
    version = "" + agent.match(regStr_ie)
  }
  //firefox
  else if (agent.indexOf("firefox") > 0) {
    let regStr_ff = /firefox\/([\d.]+)/i;
    browser = "firefox";
    version = "" + agent.match(regStr_ff)[1];
  }
  //Chrome
  else if (agent.indexOf("chrome") > 0) {
    let regStr_chrome = /chrome\/([\d.]+)/i;
    browser = "chrome";
    version = "" + agent.match(regStr_chrome)[1];
  }
  //Safari
  else if (agent.indexOf("safari") > 0 && agent.indexOf("chrome") < 0) {
    let regStr_saf = /version\/[\d.]+/i;
    browser = "safari";
    version = "" + agent.match(regStr_saf)[1];
  }
  //Opera
  else if (agent.indexOf("opera") >= 0) {
    let regStr_opera = /version\/[\d.]+/i;
    browser = "opera";
    version = "" + agent.match(regStr_opera)[1];
  } else {
    let browser = navigator.appName;
    if (browser === "Netscape") {
      let version = agent.split(";");
      let trim_Version = version[7].replace(/[ ]/g,
        "");
      let rvStr = trim_Version.match(/ [\d\.]/g).toString();
      let rv = rvStr.replace(/[,]/g, "");
      version = rv;
      browser = "IE"
    }
  }
  return {
    browser,
    version
  };
}


/*
*  url 参数获取
*  传入url地址,返回参数对象
* */
function getUrlQueryObject (urlString) {
  let reg = /([^?&=]+)=([^?=&]*)/gi,
    ret = {};
  urlString.replace(reg, function (res, $1, $2) {
    let key = decodeURIComponent($1),
      value = decodeURIComponent($2);
    ret[key] = value;
    return res;
  });
  return ret;
}


/*
*
* 操作cookie
* */

//通过cookie名字找到cookie的值,未找到则返回null
function getCookieInfo (cookie) {
  if (!cookie) return;
  let reg = /([^=?\.;]+)=([^?=;\.]+)/gi,
    ret = {};
  cookie.replace(reg, (str, $1, $2) => {
    let key = $1.trim(), value = $2.trim();
    ret[key] = value;
    return str;
  });
  return ret;
}




